(define-library (packrat helpers)
  (export as obo curry pipeline char-in?)
  (import (scheme base)
          (srfi 14))
  (begin

    (define-syntax as
      (syntax-rules ()
        ((_ name value)
         (letrec ((name value))
           name))))

    (define obo ; one-by-one
      (lambda (f . xs)
        (let loop ((cur-res f)
                   (rem-args xs))
          (if (null? rem-args)
              cur-res
              (loop (cur-res (car rem-args))
                    (cdr rem-args))))))

    (define-syntax curry
      (syntax-rules ()
        ((_ (param)
          body ...)
         (lambda (param)
           body ...))
        ((_ (param0 param* ...)
          body ...)
         (lambda (param0)
           (curry (param* ...)
                  body ...)))))

    (define pipeline
      (lambda fs
        (lambda xs
          (if (null? fs)
              (apply values xs)
              (call-with-values (lambda () (apply (car fs) xs))
                (apply pipeline (cdr fs)))))))

    (define char-in?
      (lambda (x set)
        (and (char? x)
             (char-set-contains? set x))))

  )
)
